package com.px.plan.service.impl;

import com.px.plan.service.IPlanActionRecordMediaService;
import com.px.plan.service.IPlanActionRecordService;
import com.px.plan.domain.PlanActionRecordMedia;
import com.px.plan.mapper.PlanActionRecordMediaMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;

import java.util.List;

/**
 * 行动记录媒体信息Service业务层处理
 *
 * @author WRJ
 * @date 2024-08
 */
@Service
public class PlanActionRecordMediaServiceImpl implements IPlanActionRecordMediaService
{
    @Autowired
    private PlanActionRecordMediaMapper planActionRecordMediaMapper;
    @Autowired
    private IPlanActionRecordService recordService;

    /**
     * 查询行动记录媒体信息
     *
     * @param id 行动记录媒体信息主键
     * @return 行动记录媒体信息
     */
    @Override
    public PlanActionRecordMedia selectPlanActionRecordMediaById(Long id)
    {
        return planActionRecordMediaMapper.selectPlanActionRecordMediaById(id);
    }

    /**
     * 查询行动记录媒体信息列表
     *
     * @param planActionRecordMedia 行动记录媒体信息
     * @return 行动记录媒体信息
     */
    @Override
    public List<PlanActionRecordMedia> selectPlanActionRecordMediaList(PlanActionRecordMedia planActionRecordMedia)
    {
        return planActionRecordMediaMapper.selectPlanActionRecordMediaList(planActionRecordMedia);
    }

    /**
     * 新增行动记录媒体信息
     *
     * @param planActionRecordMedia 行动记录媒体信息
     * @return 结果
     */
    @Override
    public int insertPlanActionRecordMedia(PlanActionRecordMedia planActionRecordMedia)
    {
        if (null == planActionRecordMedia.getRecordId()) {
            Long recordId = recordService.getRecordIdByActionAndSn(planActionRecordMedia.getActionId(), planActionRecordMedia.getDroneSn());
            Assert.notNull(recordId, String.format("新增失败!不存在的行动ID(%s)和SN(%s)", planActionRecordMedia.getActionId(), planActionRecordMedia.getDroneSn()));
            planActionRecordMedia.setRecordId(recordId);
        }
        return planActionRecordMediaMapper.insertPlanActionRecordMedia(planActionRecordMedia);
    }

    /**
     * 修改行动记录媒体信息
     *
     * @param planActionRecordMedia 行动记录媒体信息
     * @return 结果
     */
    @Override
    public int updatePlanActionRecordMedia(PlanActionRecordMedia planActionRecordMedia)
    {
        return planActionRecordMediaMapper.updatePlanActionRecordMedia(planActionRecordMedia);
    }

    /**
     * 批量删除行动记录媒体信息
     *
     * @param ids 需要删除的行动记录媒体信息主键
     * @return 结果
     */
    @Override
    public int deletePlanActionRecordMediaByIds(Long[] ids)
    {
        return planActionRecordMediaMapper.deletePlanActionRecordMediaByIds(ids);
    }

    /**
     * 删除行动记录媒体信息信息
     *
     * @param id 行动记录媒体信息主键
     * @return 结果
     */
    @Override
    public int deletePlanActionRecordMediaById(Long id)
    {
        return planActionRecordMediaMapper.deletePlanActionRecordMediaById(id);
    }
}
